<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <title>分享</title>
    <link rel="stylesheet" type="text/css" href="../css/aui.css" />
    <link rel="stylesheet" type="text/css" href="../css/common.css" />
    <style>
        .hbimg{padding: 0 10%;min-height: 25rem;}
        .hbimg img{border-radius: .5rem;}
        .aui-btn-danger{background-color: #e91e63 !important;}
    </style>
</head>
<body>
    <section class="aui-content aui-padded-10">
    	<div class="hbimg">
    		<img src="" width="100%">
    	</div>
    	<div class="btns aui-padded-15">
    		<div class="aui-row">
    			<div class="aui-col-xs-6 aui-padded-10">
    				<div class="aui-btn aui-btn-default aui-btn-block aui-btn-sm" onclick="share(0)" tapmode>分享链接</div>
    			</div>
    			<div class="aui-col-xs-6 aui-padded-10">
    				<div class="aui-btn aui-btn-danger aui-btn-block aui-btn-sm jb" onclick="share(1)" tapmode>分享海报</div>
    			</div>
    		</div>
    	</div>
    </section>
</body>
<script type="text/javascript" src="../script/api.js" ></script>
<script type="text/javascript" src="../script/zepto.min.js" ></script>
<script type="text/javascript" src="../script/common.js" ></script>
<script type="text/javascript">
	var sharedModule;
    apiready = function(){
        api.parseTapmode();
        sharedModule = api.require('shareAction');
        var fsDir = api.fsDir;
        $('.hbimg img').attr('src',fsDir+'/cache/haibao.png');
        getData();
    };
    function getData(){
        _loading2();
        _Ajax(window.APIServer.Hb,'post',{},'json',function(ret){
            _loading2_close();
            if (ret.code==1) {
                _SetPrefs('invite_obj',JSON.stringify(ret.data));
                $('.hbimg img').attr('src',ret.data.haibao);
                if (ret.data.is_down==1) {
                    //延迟1秒
                    var hb = ret.data.haibao;
                    setTimeout(function() {
                        //这里下载海报
                        api.download({
                            url: ret.data.haibao,
                            savePath: 'fs://cache/haibao.png',
                            report: false,
                            cache: false,
                            allowResume: true
                        }, function(ret, err) {
                            if (ret.state == 1) {
                                //下载成功
                                $('.hbimg img').attr('src',hb);
                            } else {
                                //alert(err.msg)
                            }
                        });
                    }, 500);
                }
                
            }
        });
    }
    function share(type){
        var invite_obj = JSON.parse(_GetPrefs('invite_obj')||'{}');
        //请求
        _Ajax(window.APIServer.Task,'post',{values:{type:0}},'json',function(ret){})
        if (type==0) {//链接
            sharedModule.share({
                text: invite_obj.title,
                type: 'url',
                path: invite_obj.url
            });
        }else{
            sharedModule.share({
                text: invite_obj.title,
                type: 'image',
                path:'fs://cache/haibao.png'
            });
        }
    }
</script>
</html>